
<script>
<? if($this->roleID == ''){?>
	common.setMainTitle('Thêm vai trò');
<? } else {?>
	common.setMainTitle('Sửa vai trò');
<? }?>
</script>
<?php 
    $arrActive = array(
    '0'=> '',
    '1'=> 'checked="true"',
    ''=>''
    );
	
?>


<form name="frm" id="frmSave" action="/admin/roles/save" method="POST">
<table border="0" cellpadding="0" cellspacing="0"  id="id-form">
    <tr>
        <th valign="top">Name:</th>
        <td><input type="text" class="inp-form" name="NAME" value="<?=$this->data['NAME']?>" /></td>
        <td></td>
    </tr>
    <tr>
        <th valign="top">Description:</th>
        <td>
			<textarea name="DESCRIPTION" style="height: 165px;width: 460px;" ><?=$this->data['DESCRIPTION']?></textarea>
		</td>
        <!-- <td>
            <div class="error-left" style="display:none" id="errCodePad"></div>
            <div class="error-inner" style="display:none" id="errCode" >Bạn phải nhập mã vai trò</div>
        </td> -->
    </tr>
    <tr>
        <th valign="top">Navigation:</th>
        <td>
            <select name="NAVIGATION" id="navigation" value="" > 
                <?php
                
                   $navigation = '';
                    $tab = "&nbsp;&nbsp;&nbsp;&nbsp;";
                    foreach($this->dataSources as $item1){
                        if($item1['description'] !=""){
                            $keys = array_keys($item1['controller']);
                            $navigation .= '<optgroup label="MODULE '.strtoupper($item1['description']).'" style="color:#B8B8B8;font-style:normal">';
                            for($i=0;$i<count($keys);$i++)
                            {
                                $description = $item1['controller'][$keys[$i]]['description'];
                                
                                $des = '';
                                if(strtoupper($description) != strtoupper($keys[$i])){
                                    $des = ' : '.$description;
                                }
                                
                                $navigation .= '<optgroup label="'.$tab.strtolower($keys[$i]).$des.'" value="'.$keys[$i].'" style="color:#004FA0;font-style:normal">';
                                $arr_action = $item1['controller'][$keys[$i]]['action'];
                                $keyAction = array_keys($arr_action);
                                for($ii=0;$ii<count($keyAction);$ii++)
                                {
                                    $selected = "";
                                    $value = $item1['description'].'/'.$keys[$i].'/'.$keyAction[$ii];
                                    if($this->data['NAVIGATION'] == $value){
                                        $selected = "selected ='true' ";
                                    }
                                    $desAction = '';
                                    if(strtoupper($arr_action[$keyAction[$ii]]) != strtoupper($keyAction[$ii])){
                                        $desAction = ' : '.$arr_action[$keyAction[$ii]];
                                    }
                                    $navigation .= '<option value="'.$value.'" name="'.$item1['description'].'_'.$keys[$i].'_'.$keyAction[$ii].'" style="color:#393939;" '.$selected.' >'.$tab.$tab.$tab.$keyAction[$ii].$desAction.'</option>';
                                }
                                $navigation .= "</optgroup>";
                            }
                            $navigation .= "</optgroup>";
                        }
                    }
                   echo $navigation;
                   ?>
            </select>
        </td>
        <td>
            <div class="error-left" style="display:none" id="errCodePad"></div>
            <div class="error-inner" style="display:none" id="errCode" >Bạn phải nhập mã vai trò</div>
        </td>
    </tr>
    <tr>
        <th valign="top">Is Active:</th>
        <td>
            <input type="checkbox" name="STATUS" <?=(isset($this->data->STATUS) && $this->data->STATUS == "1" ? "checked=''":''); ?> />
        </td>
        <td></td>
    </tr>
    <tr>
        <th>&nbsp;</th>
        <td valign="top">
            <input type="submit" value="Save" />
            <input type="button" value="Cancel" onclick="javascript:history.go(-1)" />
        </td>
        <td></td>
    </tr>
</table>
<input type="hidden" name="ROLEID" value="<?=$this->data['ROLEID']?>" />
</form>
<script>

selectNavigation();
function selectNavigation(){
    var currentNav = "<?=$this->data['NAVIGATION']?>";
    if(currentNav != ""){
        var arrNavi = currentNav.split('/'); 
        var navigation = arrNavi[0]+'_'+arrNavi[1]+'_'+arrNavi[2];
        var box = document.getElementById('navigation').getElementsByTagName('option');
        for(var ii = 0 ; ii< box.length;ii++){
            if(box[ii].getAttribute('name') == navigation){
               box[ii].setAttribute('selected',true);
            }
        }
    }
}
</script>